from ..common.ui.PageElement import PageElement


class Pagination(PageElement):
    '''
    fish desktop Pagination组件
    https://fish.iwhalecloud.com/fish-desktop/examples/pagination/index.html
    可以设置页码， 或者prev, first, last, next
    '''

    def select(self, param:str):
        self.wait_element_presence()
        # TODO 具体标签不可见的时候点击失败？是否需要组件自己处理
        btnDict = {'prev': '.prev', 'first': '.first', 'last': '.last', 'next': '.next'}
        param = param.strip().lower()
        if str(param) in btnDict:
            script = "$(arguments[0]).children('.pagination').children('{0}').click()".format(btnDict[param])
        else:
            script = "$(arguments[0]).children('.pagination').children('li[data-page=\"{0}\"]').click()".format(param)
        self._execute_script(script, self._get_web_element(), param)

    def click(self, param:str):
        self.wait_element_ready()
        self.select(param)

    def setValue(self, param:str):
        self.select(param)

    def get_identification(self):
        identification = {'data-ui-role': ['pagination']}
        return identification
